package mars.activity;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import bear.download.Friendsread;
import bear.download.HttpsUtils;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class newtextActivity extends Activity{
private Button share,cancel3;
private Spinner choose1;
private EditText idea,sharemen;
static boolean active = false;
String idg="";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.newtext);
		idea=(EditText)findViewById(R.id.idea);
		sharemen=(EditText)findViewById(R.id.sharemen);
		share=(Button)findViewById(R.id.share);
		cancel3=(Button)findViewById(R.id.cancel3);
	    choose1=(Spinner)findViewById(R.id.choose1);
	    String name[]=Friendsread.name1.split("\\$");			  
	    
	    List <String>list=new ArrayList<String>();
	    list.add(getString(R.string.pleasecc));
	    for(int d=0;d<Friendsread.n;d++){
	    	list.add(name[d]);
	    }
	    ArrayAdapter<String> adapter =new ArrayAdapter<String>(newtextActivity.this,R.layout.item,R.id.textViewId,list);
	    choose1.setAdapter(adapter);
	    choose1.setOnItemSelectedListener(new SpinnerOnItemSelectedListener());   
		share.setOnClickListener(new Button.OnClickListener()
    {
		public void onClick(View v) {
			// TODO Auto-generated method stub
			if(idea.getText().toString()==null){
				Toast.makeText(newtextActivity.this,R.string.kong,Toast.LENGTH_SHORT).show();
			}else{
				String lsid[]=Friendsread.lsid1.split("\\$");
				String name[]=Friendsread.name1.split("\\$");
				String scn=sharemen.getText().toString();
				for(int g=0;g<Friendsread.n;g++){
					if(scn.equals(name[g])){
					 idg=lsid[g];
					}
				}
				HttpsUtils setiead=new HttpsUtils();
				String postIdea = "username=" + landActivity.user.getText().toString() + "&lsid="+idg + "&hash=" + landActivity.hash + "&content=" + URLEncoder.encode(idea.getText().toString());
				setiead.post("https://www.loushiapp.com/?c=say&a=postsay&hash="+landActivity.hash,postIdea);
			
			Intent intentdx=new Intent();
			intentdx.setClass(newtextActivity.this, User.class);
			newtextActivity.this.startActivity(intentdx);
			System.exit(0);
			}
		}
    });
		cancel3.setOnClickListener(new Button.OnClickListener()
	    {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}	
	    });
	}
	class SpinnerOnItemSelectedListener implements OnItemSelectedListener { 
    public void onItemSelected (AdapterView<?> adapterView, View view, int position, long logicId){ 
     String selected=adapterView.getItemAtPosition(position).toString();
     if(selected!=getString(R.string.please))
     sharemen.setText(selected);
    }
    public void onNothingSelected (AdapterView<?> arg0) {  
    	System.exit(0);
    	}
	}
}

